package com.example;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * Lab2：LocalDate、LocalTime、LocalDateTime、DateTimeFormatter的使用
 *
 * @author Holinc
 * @date 2023/3/21 20:30
 */
public class Lab2 {
    public static void main(String[] args) {

        // 1. 获取当前日期、格式化日期为“yyyyMMdd”、当期日期加10天
        method1();

        // 2. 获取当前时间、格式化日期为“yyyy/MM/dd HH:mm:ss.SSS”，当前时间减1小时
        method2();

        // 3. 比较两个日期的大小
        method3();

    }

    static void method1() {
        LocalDate now = LocalDate.now();
        System.out.println(now);

        String date = DateTimeFormatter.ofPattern("yyyyMMdd").format(now);
        System.out.println(date);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String format = formatter.format(now);
        System.out.println(format);

        LocalDate newDate = now.plusDays(10);
        System.out.println(newDate);

        LocalDate localDate = now.plusYears(1);
        System.out.println(localDate);


        LocalDate plus = now.plus(2L, ChronoUnit.MONTHS);
        System.out.println(plus);



    }

    static void method2() {

    }

    static void method3() {
        System.out.println("======================method3");
        LocalDate now = LocalDate.now();
        LocalDate beforeDate = now.minusDays(10);
        System.out.println(beforeDate);
        System.out.println(now);

        boolean leapYear = now.isLeapYear();
        System.out.println(leapYear);

        boolean after = now.isAfter(beforeDate);
        System.out.println(after);

        boolean before = now.isBefore(beforeDate);
        System.out.println(before);

        boolean after1 = beforeDate.isAfter(now);
        System.out.println(after1);

    }
}
